package com.googlecode.boliang.q12;

import java.util.Deque;
import java.util.LinkedList;

public class MirrorBTree {

	public BTree getMirrorBTree(BTree rootNode) {
		
		Deque<BTree> btDeque = new LinkedList<BTree>(); 
		btDeque.add(rootNode); 
		BTree curBTree, tempBTree; 
		
		while(!btDeque.isEmpty()) {
			curBTree = btDeque.removeFirst();
			tempBTree = curBTree.getLeftChild(); 
			curBTree.setLeftChild(curBTree.getRightChild());
			curBTree.setRightChild(tempBTree); 
			
			if (curBTree.getLeftChild() != null)
				btDeque.add(curBTree.getLeftChild()); 
			if (curBTree.getRightChild() != null) 
				btDeque.add(curBTree.getRightChild()); 
		}
		
		return rootNode;
	}
}
